﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using System.Data;

public partial class EarlyWarning_WarningTrade : BasePage
{
    public EarlyWarning_WarningTrade()
    { }
    int totalrecord = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }
    private void BindData()
    {
        HZ.Supervise.IBLL.IBLL_PreWarning iPreWarning = HZ.Supervise.BLLFactory.IBLL_PreWarning();
        HZ.Supervise.Model.TradePreWarning mTradePreWarning = new TradePreWarning();
        mTradePreWarning.IsUsing = true;       
        DataTable dt = new DataTable();
        dt = iPreWarning.GetTradePreWarning(mTradePreWarning, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out totalrecord);
        if (dt.Rows.Count > 0)
        {
            foreach (DataRow row in dt.Rows)
            {
                if (row["HospitalID"].ToString() != "所有医院" && row["HospitalName"] == DBNull.Value)
                {
                    row["HospitalName"] = "多家医院";
                }
                if (row["CompanyID_PS"].ToString() != "所有企业" && row["CompanyName"] == DBNull.Value)
                {
                    row["CompanyName"] = "多家企业";
                }
            }
        }
        AspNetPager1.RecordCount = totalrecord;
        this.gvwInfo.DataSource = dt;
        this.gvwInfo.DataBind();
   
    }
    protected void btnForbidden_Click(object sender, EventArgs e)
    {
        HZ.Supervise.IBLL.IBLL_PreWarning iPreWarning = HZ.Supervise.BLLFactory.IBLL_PreWarning();
        string strchkID = Request["chkID"];
        if (!string.IsNullOrEmpty(strchkID))
        {
            try
            {
                string[] arryID = strchkID.Split(',');
                for (int i = 0; i < arryID.Length; i++)
                {
                    HZ.Supervise.Model.TradePreWarning mTradePreWarning = new HZ.Supervise.Model.TradePreWarning();
                    mTradePreWarning.TradePreWarningID = arryID[i];
                    mTradePreWarning.IsUsing = false;
                    iPreWarning.UpdateTradePreWarning(mTradePreWarning);
                }
                HZ.Web.WebUtil.Alert("操作成功！");
                BindData();
            }
            catch (Exception ex)
            {
                HZ.Web.WebUtil.Alert(ex.Message);
            }
        }
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindData();
    }
    protected void gvwInfo_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label LabType = (Label)e.Row.FindControl("labType");
            Label LabLeve = (Label)e.Row.FindControl("labLeve");

            switch (LabType.Text)
            {
                case "0":
                    LabType.Text = "医院已提交采购单企业未确认";
                    break;
                case "1":
                    LabType.Text = "企业已确认定单医院未入库";
                    break;
                case "2":
                    LabType.Text = "企业已开发票中心未审核";
                    break;
                case "3":
                    LabType.Text = "医院已提交退货单企业未确认";
                    break;
                case "4":
                    LabType.Text = "医院已提交回款单企业未确认";
                    break;
                case "5":
                    LabType.Text = "医院已入库未回款";
                    break;
            }

            switch (LabLeve.Text)
            {
                case "1":
                    LabLeve.Text = "一级预警";
                    break;
                case "2":
                    LabLeve.Text = "二级预警";
                    break;
                case "3":
                    LabLeve.Text = "三级预警";
                    break;
            }

            string _AreaID = ((DataRowView)e.Row.DataItem).Row.ItemArray[1].ToString();
            string _HospitalID = ((DataRowView)e.Row.DataItem).Row.ItemArray[4].ToString();
            string _CompanyId = ((DataRowView)e.Row.DataItem).Row.ItemArray[5].ToString();

            e.Row.Cells[2].Attributes.Add("onclick", "javascript:window.open('showHospital.aspx?HospitalID=" + Server.UrlEncode(_HospitalID) + "&&AreaID=" + Server.UrlEncode(_AreaID) + "','showHospital1','width=600,height=400,resizable=0,scrollbars=0, status=0, toolbar=0, menubar=0')");
            e.Row.Cells[3].Attributes.Add("onclick", "javascript:window.open('showCompany.aspx?CompanyID=" + Server.UrlEncode(_CompanyId) + "','showCompany','width=600,height=400,resizable=0,scrollbars=0, status=0, toolbar=0, menubar=0')");

            e.Row.Cells[2].Attributes.Add("onmouseover", "this.style.color='red'");
            e.Row.Cells[2].Attributes.Add("onmouseout", "this.style.color=''");

            e.Row.Cells[3].Attributes.Add("onmouseover", "this.style.color='red'");
            e.Row.Cells[3].Attributes.Add("onmouseout", "this.style.color=''");

        }
    }
}
